<!DOCTYPE html>
<html>
<head>
  <title>发布营销活动</title>
    <script>document.domian="12301.cc";</script>
</head>
<body>
<iframe src="about:blank" style="display: block;" id="hideFrame" name="hideFrame" frameborder="0"></iframe>

<form id="imgUpload_form" action="http://s.12301.cc/pft/marketing/marketing.php" method="post" enctype="multipart/form-data" target="hideFrame">
    <input name="action" value="upload" type="hidden"/>
    <input name="auth" value="upload" type="hidden"/>
    <input name="imgUpload_fileVal" value="upload" type="hidden"/>
    <input type="file" id="imgUpload_inpFile" name="image"/>
    <input type="text" name="" id="showimgPathInp"/>
    <input type="button" id="submitImgUploadBtn" value="submit"/>
    <div id="uploadResultCon"></div>
    <div id="uploadFailTip"></div>
</form>
<script src="http://www.12301.cc/js/jquery-1.9.1.min.js"></script>
<script>
    $("#submitImgUploadBtn").on("click",function(e){
        //var active = $("#imgDialog-tabNavCon").children(".active");

        ImgUpload.upload();

    })
    $("#imgUpload_inpFile").on("change",function(e){
        ImgUpload.onFileChange(e.currentTarget);
    })
    var ImgUpload = (function(){

        function onFileChange(inpFile){
            var path = inpFile.value;
            path = path.replace(/c:\\fakepath\\/gi,"");
            path.replace(/c:/ig,"");
            $("#imgUpload_fileVal").val(path);
        }
        function upload(){
            // $("#image-container").hide();
            onloading();
            $("#imgUpload_form").submit();
        }
        function onloading(){
            var imgname = $("#imgUpload_fileVal").val();
            var loadingImg = "http://www.12301.cc/images/other/loading_1.gif";
            var html = '<div class="uploadResult loading"><div class="con"><img src="'+loadingImg+'"/><span class="text">正在上传图片...</span></div></div>';
            $("#uploadFailTip").hide();
            $("#uploadResultCon").html(html);
        }
        function onload(data){ //上传图片完成
            console && console.log("上传图片完成，未知是否成功");
            if(data.status == "ok" && data.key){
                console && console.log("上传图片成功");
                onSuccess(data);
            }else{
                console && console.log("上传图片失败");
                onFail(data)
            }
        }
        function onSuccess(data){
            var path = data.key;
            var html = '<div class="uploadResult success"><div class="con"><img src="'+path+'"/></div></div>';
            $("#uploadResultCon").html(html);
            $("#showimgPathInp").val(path);
            WXB.G.Alert("success",'<p style="width:150px;">上传图片成功</p>',2000)
        }
        function onFail(data){
            var img = '<img src="http://www.12301.cc/wx_public/images/nopic.jpg"  class="img-responsive img-thumbnail" width="150">';
            $("#uploadResultCon").html(img);
            $("#uploadFailTip").show();
            WXB.G.Alert("fail",'<p style="width:150px;">上传图片失败</p>')
        }

        return{
            onFileChange : onFileChange,
            upload : upload,
            onload : onload
        }

    })();
</script>
</body>
</html>